package cn.farm.farm.Mapper.CommonMapper;


import cn.farm.farm.Entity.Common.Enemy;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface EnemyMapper extends Mapper<Enemy> {


    @Select("select enemyID,chineseName,latinName,alias,imageID from enemy where chineseName like CONCAT('%',#{name},'%')")
    @Results({
            @Result(column = "imageID" , property = "image",
                    many=@Many(select = "cn.farm.farm.Mapper.CommonMapper.MatchMapper.getimageID",fetchType= FetchType.EAGER))
    })
    List<Enemy> likeSelect(@Param(value = "name") String name);


    @Select("select * from enemy where enemyID =#{enemyid}")
    @Results({
            @Result(column = "imageID" , property = "image",
                    many=@Many(select = "cn.farm.farm.Mapper.CommonMapper.MatchMapper.getimageID",fetchType= FetchType.EAGER))
    })
    Enemy selectByKey(@Param(value = "enemyid") Integer enemyid);

    @Select("select count(*) from enemy where category in (select bioID from biologycategory where species = #{species}) ")
    Integer selectByCate(@Param(value = "species") String species);

    @Select("select * from enemy where category in (select bioID from biologycategory where species = #{species} ) ")
    @Results({
            @Result(column = "imageID" , property = "image",
                    many=@Many(select = "cn.farm.farm.Mapper.CommonMapper.MatchMapper.getimageID",fetchType= FetchType.EAGER))
    })
    List<Enemy> selectByCategory(@Param(value = "species") String species);
}
